/** @odoo-module **/
import { CharField ,charField} from "@web/views/fields/char/char_field";
import { registry } from "@web/core/registry";
import { useService, useBus } from "@web/core/utils/hooks";
import { RelationalModel } from "@web/model/relational_model/relational_model";
import { EventBus, onWillStart, onWillUpdateProps, status, useComponent } from "@odoo/owl";
import { rpc } from "@web/core/network/rpc";
import { ExportDataDialog } from "@web/views/view_dialogs/export_data_dialog";
import { ExportDataDialogTZ } from "./ExportDataDialogTZ";
import { hiprintDesign } from "./hiprintDesign";
export class CharFieldtuozhan extends CharField {
    static template = "CharFieldtuozhan";
    setup() {
        super.setup();
        this.dialogService = useService("dialog");
        this.action = useService("action");
        const component = useComponent();
 
        const services = {};
        for (const key of RelationalModel.services) {
            services[key] = useService(key);
        }
        services.orm = services.orm || useService("orm");
        this.sv=services;
        this.env1=component.env;

    
 

        
    }
    async getExportedFields(model, import_compat, parentParams) {
        let domain = this.model.root.domain;
      
        return await rpc("/web/export/get_fields", {
            ...parentParams,
            model,
            domain,
            import_compat,
        });
    }
   async designmoban(){
    let sss1=this;
    this.dialogService.add(hiprintDesign, {queren1:function (params) {
        sss1.props.record.update({moban:JSON.stringify(params)})
    } ,ziduans:JSON.parse(this.props.record.data.ziduans) ,  moban: this.props.record.data.moban
        ? JSON.parse(this.props.record.data.moban)
        : {}});
   }
   async pickziduan(){
       let jjj=this;
       await this.createModel(this.props.record.data.moxing_model_name, [], ["name"]);
       let zds=[];
        if ( jjj.props.record.data.ziduans) {
             zds=JSON.parse(jjj.props.record.data.ziduans);
        }
         const dialogProps = {
             context: this.env1.model.config.context,
            defaultExportList:zds,
            baocunziduan:async function (value) { 
                console.log(value);
                jjj.props.record.update({ziduans:JSON.stringify(value)})   
               
            },

            download: function (params) {
                
            },
            getExportedFields: this.getExportedFields.bind(this),
         root:this.model.root,
         };
         this.dialogService.add(ExportDataDialogTZ, dialogProps);
    }
    async createModel(resModel, domain = [], fields = []) {
        let pz = {  
            config: {  
                resModel: resModel,  
                domain: domain,  
                fields: fields,  
                activeFields: [],
                orderBy: [],  
                groupBy: [],  
                context: this.env1.model.config.context,  
                searchViewArch: "<search/>",  
                searchViewFields: {},  
                searchViewId: false,  
                activateFavorite: true,  
                loadIrFilters: false,  
                searchMenuTypes: ["filter", "groupBy", "favorite"],  
                display: {  
                    searchPanel: true  
                }  
            }  
        };  

        const model = new RelationalModel(this.env1,  pz,this.sv);
       await model.load();
        this.model = model;
    }
 
}
export const charFieldTuozhan = {
    ...charField,            // 复制所有原有配置
    component: CharFieldtuozhan,    // 替换为你的新组件
    displayName: "Text (拓展)",  // 你可以修改显示名称
    supportedTypes: ["chartuozhan"], // 注册新类型名，防止覆盖原有 char
};
registry.category("fields").add("chartuozhan", charFieldTuozhan);
console.log(12345)
//addons\web\static\src\views\fields\char\char_field.js